<template>
	<m-layout class="box" :title="$t('修改登录密码')" gap="30">
		<m-text block spa="0 0 20 0">{{$t('邮箱')}}</m-text>
		<m-input class="form-Item  "  v-model="phonemaill" :placeholder="$t('请输入您的邮箱')">
		</m-input>
		<m-text block spa="20 0">{{$t('验证码')}}</m-text>
		<m-input class="form-Item  form-Item-1 " v-model="code" :placeholder="$t('请输入您的验证码')">
			<m-sendCode :value="phonemaill" slot="right":title="$t('获取')"></m-sendCode>
		</m-input>
		<m-text block spa="20 0">{{$t('新密码')}}</m-text>
		<m-input class="form-Item"  type="password" v-model="password" :placeholder="$t('密码必须')"> </m-input>
		<m-text block spa="20 0">{{$t('再次确认密码')}}</m-text>
		<m-input class="form-Item" type="password" @blur="secondary" v-model="password2" :placeholder="$t('再次确认密码')">
		</m-input>
		<m-button spa="100 0 0"  block :loading="resetLoading" @click="resetpwd">{{$t('确认修改')}}</m-button>
	</m-layout>
</template>

<script>
	import { email, mobile,enHisNum } from '@/libs/fn/verify.js'
	import { SetPassword } from '@/api/Users.js'
	export default {
		data() {
			return {
				phonemaill: "",
				oldpassword: '',
				password: '',
				password2: '',
				code: '',

				resetLoading: false,
				timeObj: '',
				timer: 0,
				codeLoading: false,
			};
		},
		mounted() {
			
		},
		methods: {
			
			secondary() {
				if (this.password != this.password2) {
					this.Toast(this.$t('两次密码输入有误'))
				}
			},

			async resetpwd() {
				if (!this.phonemaill) {
					this.Toast(this.$t('请输入您的邮箱'))
					return
				}
				if (!this.password) {
					this.Toast(this.$t('请输入密码'))
					return
				}
				if (!this.code) {
					this.Toast(this.$t('请输入您的验证码'))
					return
				}
				if (!enHisNum(this.password)) {
					this.Toast(this.$t('密码必须'))
					return
				}
				if (this.password != this.password2) {
					this.Toast(this.$t('两次密码输入有误'))
					return
				}
				
				this.resetLoading = true;
				const success = await SetPassword({
					phonemaill: this.phonemaill,
					password: this.password,
					code: this.code,
				})
				this.resetLoading = false;
				if (success) {
					await this.sleep(1000)
					this.Jump()
				}
			},
		}
	}
</script>

<style lang="scss">
	text {
		display: block;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 400;

	}

	.form-Item {
		margin: 40rpx 0;
		// border: 1px solid #4D536B;
		border-radius: 15rpx;
		padding: 20rpx 28rpx;
		box-sizing: border-box;

		input {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 400;
		}

		/deep/ uni-textarea {
			width: 100%;
			font-size: 26rpx;
			margin: 0;

			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 400;

		}
	}

	.form-Item-1 {
		padding: 10rpx 28rpx;
	}
</style>